﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="ServiceCompletion.aspx.cs" Inherits="TireService.Web.View.ServiceView.ServiceCompletion" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgPacking" alt="" src="~/Images/Medium/gear_ok.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblTaskCompletion" runat="server" Text="Færdigmeld servicekørsel"></asp:Label></h3>
            </td>
        </tr>
    </table>
    <hr />

    <!-- Javascript of action dropdown list -->
    <script language="javascript" type="text/javascript">

        // Function that handles actions selected in dropdown list
        function ActionClicked() {

            // Get selected action from dropdownlist
            var id = ddlAction.GetValue();

            if (id != null && id != 0) {
                
                // Mark selected as completed
                if (id == 1) {
                    // Get selected items in gridview and trigger event MarkServiceCompletedNoEmail 
                    gvServiceCompletion.GetSelectedFieldValues('ServiceCarScheduleDetailId', MarkServiceCompletedNoEmail);
                }

                // Mark selected as completed and send out email to customer
                if (id == 2) {
                    // Get selected items in gridview and trigger event MarkServiceCompletedSendEmail 
                    gvServiceCompletion.GetSelectedFieldValues('ServiceCarScheduleDetailId', MarkServiceCompletedSendEmail);
                }
            }
            else {
                alert('Ingen handling valgt');
            }
        }

        // Perform callback that marks selected services as completed
        function MarkServiceCompletedNoEmail(selectedValues) {
            if (selectedValues.length == 0) return;

            var input = "MarkCompletedNoEmail" + ',' + selectedValues;
            callMarkServiceCompleted.PerformCallback(input);
        }

        // Perform callback that marks selected services as completed and send email to customer
        function MarkServiceCompletedSendEmail(selectedValues) {
            if (selectedValues.length == 0) return;

            var input = "MarkCompletedSendEmail" + ',' + selectedValues;
            callMarkServiceCompleted.PerformCallback(input);
        }

        // Function that runs when server side completed processing of handling markservice as completed
        function OnCallbackMarkServiceCompleted(s, e) {
            gvServiceCompletion.PerformCallback();

            alert('Handling udført');
        }

        // Function that return error in case callback to server failed
        function CallBackError(s, e) {
            alert('Fejl opstod: ' + e.message);
        }

    </script>

    <dx:ASPxCallback ID="callMarkServiceCompleted" ClientInstanceName="callMarkServiceCompleted" runat="server" OnCallback="callMarkServiceCompleted_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackMarkServiceCompleted" />
    </dx:ASPxCallback>
                
    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlAction" ClientInstanceName="ddlAction" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="true" Value="0" Text="-- Handling --" />
                        <dx:ListEditItem Value="1" Text="Færdigmeld valgte" />
                        <dx:ListEditItem Value="2" Text="Færdigmeld valgte - Send email" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { ActionClicked(); }" />
                </dx:ASPxButton>
            </td>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlExport" ClientInstanceName="ddlExport" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="True" Value="0" Text="Export pdf" />
                        <dx:ListEditItem Value="1" Text="Export xls" />
                        <dx:ListEditItem Value="2" Text="Export csv" />
                        <dx:ListEditItem Value="3" Text="Export rtf" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnExport" runat="server" Text="Exporter" OnClick="btnExport_Click" Width="75px" >
                </dx:ASPxButton>
            </td>
            <td align="right">
                <asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:DropDownList ID="ddlView" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ddlView_SelectedIndexChanged">
                    <asp:ListItem Value="0">Grupper efter Lager og Servicebil</asp:ListItem>
                    <asp:ListItem Value="1">Grupper efter Lager og Lagerplads</asp:ListItem>
                </asp:DropDownList>
                &nbsp;
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
    </table>          
    <hr />

    <dx:ASPxGridView ID="gvServiceCompletion" runat="server" ClientInstanceName="gvServiceCompletion" 
        KeyFieldName="TaskId" Width="100%" AutoGenerateColumns="False" EnableCallBacks="True" OnCustomCallback="gvServiceCompletion_CustomCallback" 
        oncustomunboundcolumndata="gvServiceCompletion_CustomUnboundColumnData">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Border BorderWidth="0px" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="False" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} servicekørsler)" 
                Text="Side {0} af {1} ({2} servicekørsler)" />
        </SettingsPager>
        <SettingsBehavior AllowFocusedRow="false" ConfirmDelete="True" AllowGroup="true" AllowDragDrop="true" />
        <Columns>
            <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="1">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvServiceCompletion.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataColumn FieldName="ScheduleDate" VisibleIndex="2" Caption="Dato">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ServiceCarScheduleDetailId" Visible="false" VisibleIndex="2" Caption="ServiceCarScheduleDetailId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CarId" Visible="false" VisibleIndex="2" Caption="CarId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="0" Caption="Kundenr">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CustomerId">
                </PropertiesHyperLinkEdit>
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataColumn FieldName="CustomerId" Visible="false" VisibleIndex="3" Caption="CustomerId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TireSetId" Visible="false" VisibleIndex="4" Caption="TireSetId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ContainerId" Visible="false" VisibleIndex="5" Caption="ContainerId">
            </dx:GridViewDataColumn>
            <%--<dx:GridViewDataColumn FieldName="TaskId" VisibleIndex="3" Caption="Opgavenr">
            </dx:GridViewDataColumn>--%>
            <dx:GridViewDataColumn FieldName="ContainerNumber" VisibleIndex="4" Caption="ContainerNumber">
            </dx:GridViewDataColumn>
            <dx:GridViewDataTextColumn FieldName="ServiceCarDescription" VisibleIndex="4" Caption="Servicebil">
            </dx:GridViewDataTextColumn>
            <%--<dx:GridViewDataColumn FieldName="SequenceNumber" VisibleIndex="6" Caption="Sekvensnr">
            </dx:GridViewDataColumn>--%>
            <dx:GridViewDataTextColumn FieldName="CargoRoomNumber" VisibleIndex="5" Caption="Lagerplads">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="CarBrandDescription" VisibleIndex="6" Caption="Bilmærke">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataColumn FieldName="Model" VisibleIndex="7" Caption="Model">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="8" Caption="Reg.nr.">    
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TireTypeDescription" VisibleIndex="9" Caption="Dæktype">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TireBrandDescription" VisibleIndex="10" Caption="Dækmærke">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TireDimensions" UnboundType="String" VisibleIndex="11" Caption="Dimensioner">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="DummyTireSet" VisibleIndex="12" ToolTip="Angiver om dette er et dummy hjulsæt pga. vi endnu ikke har været ude ved kunden og fået hjul med hjem" Caption="Dummy">
            </dx:GridViewDataColumn>
        </Columns>
        <Templates>
            <DetailRow>
                Opgavedetaljer
                <br />
                <dx:ASPxGridView ID="gvTaskDetail" ClientInstanceName="gvTaskDetail" runat="server" KeyFieldName="TaskDetailId"
                    Width="100%" OnBeforePerformDataSelect="gvTaskDetail_DataSelect">
                    <Columns>
                        <dx:GridViewDataColumn FieldName="TaskDetailId" Caption="Id" VisibleIndex="1" />
                        <dx:GridViewDataColumn FieldName="TaskDetailTypeId" Caption="Type" Visible="false" VisibleIndex="2" />
                        <dx:GridViewDataColumn FieldName="Description" Caption="Beskrivelse" VisibleIndex="2" />
                        <dx:GridViewDataColumn FieldName="EstimatedTime" Caption="Estimeret tid" VisibleIndex="2" />
                        <dx:GridViewDataColumn FieldName="Amount" Caption="Antal" VisibleIndex="3" />
                        <dx:GridViewDataColumn FieldName="NoteToEmployee" Caption="Note" VisibleIndex="4" />
                        <dx:GridViewDataColumn FieldName="Completed" Caption="Afsluttet" VisibleIndex="5" />
                        <dx:GridViewDataColumn FieldName="Cancelled" Caption="Annulleret" VisibleIndex="6" />
                    </Columns>
                </dx:ASPxGridView>
            </DetailRow>
        </Templates>
        <SettingsDetail ShowDetailRow="true" />                                             
    </dx:ASPxGridView>              
                
    <dx:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvServiceCompletion">
    </dx:ASPxGridViewExporter>

</asp:Content>
